//
//  ViewController.swift
//  XXIOT
//
//  Created by xx on 2024/8/19.
//

import UIKit
import CocoaMQTT
import FastSwiftSDK


class ViewController: UIViewController {
    
//    var mqtt5:CocoaMQTT5!
    
    private lazy var btn : FastButton = {
        let btn =  FastButton.init(title: "开关", imgName: "",color: themeColor ,font:UIFont.system(15));
        btn.cornerRadius = 6
        btn.border(color: themeColor, width: 1)
        btn.click = { [weak self] in
            self?.btnAction()
        }
        return  btn
    } ()
    
   

    
    var mqtt =  XXMQTT()
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        FastLog.shared.level = .DEBUG
        
        self.view.addSubview(btn)
        mqtt.content(host: "8.137.99.64", username: "zhaonx", password: "Zhaonx123..",topics: [XXTOPIC.PUBLIC.rawValue])
        mqtt.connectCallBack = { string in
            FastLog.debug(string)
        }
        mqtt.msgCallBack = { topics , msg in
            FastLog.debug(topics)
            FastLog.debug(msg)
        }
        
    }
    
    override func viewWillLayoutSubviews() {
        super.viewWillLayoutSubviews()
    
        btn.snp_makeConstraints { make in
            make.top.left.equalTo(50)
            make.size.equalTo(50)
        }
        
    }
    
    
    func btnAction(){
        print("btnAction----")
        let roperties =  MqttPublishProperties()
        
//        if switchState == true{
//            mqtt.sende(topic: "XX/RELAY/SWITCH/84:CC:A8:97:E0:0B", msg: "OFF")
////            mqtt5.publish("XX/RELAY/SWITCH/84:CC:A8:97:E0:0B", withString: "OFF", properties: roperties)
//            
////            let msg = CocoaMQTTMessage(topic: "XX/RELAY/SWITCH/84:CC:A8:97:E0:0B", string: "OFF")
////            mqtt.publish(msg)
//        }else{
//            mqtt.sende(topic: "XX/RELAY/SWITCH/84:CC:A8:97:E0:0B", msg: "ON")
////            let msg = CocoaMQTTMessage(topic: "XX/RELAY/SWITCH/84:CC:A8:97:E0:0B", string: "ON")
////            mqtt.publish(msg)
//            
////            mqtt5.publish("XX/RELAY/SWITCH/84:CC:A8:97:E0:0B", withString: "ON", properties: roperties)
//        }

       
    }
    

}

